require('./login.less')
require('../../assets/css/index.less')
const { gete } = require('../../utils/dom');

const dom = require('../../utils/dom')
const https = require('../../utils/https');
const local = require('../../utils/local');
dom.ready(function() {
    dom.addevent("header", function() {
        location.href = "register.html"
    })
    dom.addevent('#login', function() {
        //只要账号和密码都有写,就可以发ajax
        if (tel.value && psw.value) {
            //发ajax
            https.post('/api/user/login', {
                account: tel.value,
                password: psw.value
            }, function(res) {
                //参数解构赋值操作
                let { errno, data } = res;
                //判定
                if (errno == 0) {
                    alert('恭喜您,登陆成功!')
                        //存储用户信息 和 token
                    local.set('user', data);

                    //存token的值
                    local.set('tk', data.token)

                    //跳转到首页
                    location.href = 'home.html'
                } else {
                    alert('登陆失败!,账号或密码不正确')
                }

            })
        }
    })

})